package com.example.mscluster.consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class ConsumerController {

    @Autowired
    private UserFeignClient userFeignClient;

    @GetMapping("/get/all")
    public String comsumerAllUser() {
        String url="http://127.0.0.1:18083/provider/user/all";
//        ResponseEntity<JSONObject> requestObject = restTemplate.postForEntity(gspClientTokenUrl+ "/gsp-oauth/client/token",
//                requestEntity, JSONObject.class);
//        String body = JsonUtil.object2Json(bizObject);
//        String json = this.getRequestParams(body);
//        String url = dadaConfig.getApiPrefix() + requestPath;
        System.out.println("http request to order :"+url);
        sleepRandomSec();
//        return OkHttpUtils.doGet(url);
        return userFeignClient.getAllUsers();
    }

    public void sleepRandomSec() {
        Random rand = new Random();
        long sleepMill=Math.round(Math.abs(rand.nextGaussian()*100));
        try {
            System.out.println("sleep "+sleepMill+" millsec!");
            Thread.sleep(sleepMill);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
